home *** CD-ROM | disk | FTP | other *** search
open in:
MacOS 8.1
|
Win98
|
DOS
browse contents |
view JSON data
|
view as text
This file was processed as: Mailbox/MIME Entity
(archive/mbox).
Confidence | Program | Detection | Match Type | Support
|
---|
100%
| dexvert
| Newsgroup Content (archive/news)
| magic
| Supported |
100%
| dexvert
| Mailbox/MIME Entity (archive/mbox)
| magic
| Supported |
1%
| dexvert
| Text File (text/txt)
| fallback
| Supported |
100%
| file
| news text
| default
| |
99%
| file
| C++ source text
| default
| |
98%
| file
| C source text
| default
| |
97%
| file
| C source, ASCII text
| default
| |
100%
| checkBytes
| Printable ASCII
| default
| |
100%
| dexmagic
| PrintFox/Pagefox WEAK
| default
| |
100%
| perlTextCheck
| Likely Text (Perl)
| default
| |
100%
| siegfried
| fmt/950 MIME Email (1.0)
| default
| |
100%
| detectItEasy
| Format: plain text[LF]
| default (weak)
| |
100%
| xdgMime
| message/news
| default
|
|
hex view+--------+-------------------------+-------------------------+--------+--------+
|00000000| 50 61 74 68 3a 20 69 73 | 6f 6e 65 77 73 2e 62 62 |Path: is|onews.bb|
|00000010| 6e 2e 68 70 2e 63 6f 6d | 21 6e 65 77 73 0a 46 72 |n.hp.com|!news.Fr|
|00000020| 6f 6d 3a 20 4a 6f 65 6c | 20 57 65 6e 67 65 72 20 |om: Joel| Wenger |
|00000030| 3c 6a 77 65 6e 67 65 72 | 40 61 34 34 33 30 65 64 |<jwenger|@a4430ed|
|00000040| 63 2e 65 73 72 2e 68 70 | 2e 63 6f 6d 3e 0a 4e 65 |c.esr.hp|.com>.Ne|
|00000050| 77 73 67 72 6f 75 70 73 | 3a 20 63 6f 6d 70 2e 6c |wsgroups|: comp.l|
|00000060| 61 6e 67 2e 63 2b 2b 0a | 53 75 62 6a 65 63 74 3a |ang.c++.|Subject:|
|00000070| 20 52 65 3a 20 46 75 6e | 63 74 69 6f 6e 20 6f 76 | Re: Fun|ction ov|
|00000080| 65 72 6c 6f 61 64 69 6e | 67 20 70 72 6f 62 6c 65 |erloadin|g proble|
|00000090| 6d 0a 44 61 74 65 3a 20 | 54 75 65 2c 20 33 30 20 |m.Date: |Tue, 30 |
|000000a0| 4a 61 6e 20 31 39 39 36 | 20 31 37 3a 35 39 3a 34 |Jan 1996| 17:59:4|
|000000b0| 32 20 2d 30 35 30 30 0a | 4f 72 67 61 6e 69 7a 61 |2 -0500.|Organiza|
|000000c0| 74 69 6f 6e 3a 20 48 65 | 77 6c 65 74 74 2d 50 61 |tion: He|wlett-Pa|
|000000d0| 63 6b 61 72 64 20 43 6f | 2e 0a 4d 65 73 73 61 67 |ckard Co|..Messag|
|000000e0| 65 2d 49 44 3a 20 3c 33 | 31 30 45 41 32 44 45 2e |e-ID: <3|10EA2DE.|
|000000f0| 36 39 32 37 40 61 34 34 | 33 30 65 64 63 2e 65 73 |6927@a44|30edc.es|
|00000100| 72 2e 68 70 2e 63 6f 6d | 3e 0a 52 65 66 65 72 65 |r.hp.com|>.Refere|
|00000110| 6e 63 65 73 3a 20 3c 44 | 4c 42 78 6f 48 2e 47 4c |nces: <D|LBxoH.GL|
|00000120| 77 40 61 72 69 65 6c 2e | 63 73 2e 79 6f 72 6b 75 |w@ariel.|cs.yorku|
|00000130| 2e 63 61 3e 0a 4e 4e 54 | 50 2d 50 6f 73 74 69 6e |.ca>.NNT|P-Postin|
|00000140| 67 2d 48 6f 73 74 3a 20 | 61 34 34 33 30 65 64 63 |g-Host: |a4430edc|
|00000150| 2e 65 73 72 2e 68 70 2e | 63 6f 6d 0a 4d 69 6d 65 |.esr.hp.|com.Mime|
|00000160| 2d 56 65 72 73 69 6f 6e | 3a 20 31 2e 30 0a 43 6f |-Version|: 1.0.Co|
|00000170| 6e 74 65 6e 74 2d 54 79 | 70 65 3a 20 74 65 78 74 |ntent-Ty|pe: text|
|00000180| 2f 70 6c 61 69 6e 3b 20 | 63 68 61 72 73 65 74 3d |/plain; |charset=|
|00000190| 75 73 2d 61 73 63 69 69 | 0a 43 6f 6e 74 65 6e 74 |us-ascii|.Content|
|000001a0| 2d 54 72 61 6e 73 66 65 | 72 2d 45 6e 63 6f 64 69 |-Transfe|r-Encodi|
|000001b0| 6e 67 3a 20 37 62 69 74 | 0a 58 2d 4d 61 69 6c 65 |ng: 7bit|.X-Maile|
|000001c0| 72 3a 20 4d 6f 7a 69 6c | 6c 61 20 32 2e 30 62 33 |r: Mozil|la 2.0b3|
|000001d0| 20 28 58 31 31 3b 20 49 | 3b 20 48 50 2d 55 58 20 | (X11; I|; HP-UX |
|000001e0| 41 2e 30 39 2e 30 35 20 | 39 30 30 30 2f 37 31 35 |A.09.05 |9000/715|
|000001f0| 29 0a 54 6f 3a 20 49 41 | 4e 20 4a 20 43 4f 4c 4f |).To: IA|N J COLO|
|00000200| 4d 42 59 20 3c 63 73 39 | 31 31 31 30 38 40 61 72 |MBY <cs9|11108@ar|
|00000210| 69 65 6c 2e 63 73 2e 79 | 6f 72 6b 75 2e 63 61 3e |iel.cs.y|orku.ca>|
|00000220| 0a 0a 49 41 4e 20 4a 20 | 43 4f 4c 4f 4d 42 59 20 |..IAN J |COLOMBY |
|00000230| 77 72 6f 74 65 3a 0a 3e | 20 0a 3e 20 49 20 68 61 |wrote:.>| .> I ha|
|00000240| 76 65 20 74 68 65 20 66 | 6f 6c 6c 6f 77 69 6e 67 |ve the f|ollowing|
|00000250| 20 63 6f 64 65 20 77 68 | 69 63 68 20 69 6e 20 77 | code wh|ich in w|
|00000260| 68 69 63 68 20 74 68 65 | 20 66 75 6e 63 74 69 6f |hich the| functio|
|00000270| 6e 20 63 61 6c 6c 20 6f | 66 20 66 28 29 20 69 6e |n call o|f f() in|
|00000280| 73 69 64 65 0a 3e 20 66 | 75 6e 63 74 69 6f 6e 20 |side.> f|unction |
|00000290| 67 28 29 20 64 6f 65 73 | 6e 27 74 20 62 65 68 61 |g() does|n't beha|
|000002a0| 76 65 20 74 68 65 20 77 | 61 79 20 49 20 65 78 70 |ve the w|ay I exp|
|000002b0| 65 63 74 65 64 20 69 74 | 20 74 6f 2e 0a 3e 20 0a |ected it| to..> .|
|000002c0| 3e 20 63 6c 61 73 73 20 | 42 3b 0a 3e 20 63 6c 61 |> class |B;.> cla|
|000002d0| 73 73 20 43 3b 0a 3e 20 | 0a 3e 20 63 6c 61 73 73 |ss C;.> |.> class|
|000002e0| 20 41 0a 3e 20 7b 0a 3e | 20 20 20 20 76 69 72 74 | A.> {.>| virt|
|000002f0| 75 61 6c 20 76 6f 69 64 | 20 66 28 42 2a 29 3b 0a |ual void| f(B*);.|
|00000300| 3e 20 20 20 20 76 69 72 | 74 75 61 6c 20 76 6f 69 |> vir|tual voi|
|00000310| 64 20 66 28 43 2a 29 3b | 0a 3e 20 7d 3b 0a 3e 20 |d f(C*);|.> };.> |
|00000320| 0a 3e 20 63 6c 61 73 73 | 20 42 3a 20 70 75 62 6c |.> class| B: publ|
|00000330| 69 63 20 41 0a 3e 20 7b | 0a 3e 20 20 20 20 76 6f |ic A.> {|.> vo|
|00000340| 69 64 20 66 28 42 2a 29 | 3b 0a 3e 20 20 20 20 76 |id f(B*)|;.> v|
|00000350| 6f 69 64 20 66 28 43 2a | 29 3b 0a 3e 20 7d 3b 0a |oid f(C*|);.> };.|
|00000360| 3e 20 0a 3e 20 63 6c 61 | 73 73 20 43 3a 20 70 75 |> .> cla|ss C: pu|
|00000370| 62 6c 69 63 20 41 0a 3e | 20 7b 0a 3e 20 20 20 20 |blic A.>| {.> |
|00000380| 76 6f 69 64 20 66 28 42 | 2a 29 3b 0a 3e 20 20 20 |void f(B|*);.> |
|00000390| 20 76 6f 69 64 20 66 28 | 43 2a 29 3b 0a 3e 20 7d | void f(|C*);.> }|
|000003a0| 3b 0a 3e 20 0a 3e 20 76 | 6f 69 64 20 67 28 41 2a |;.> .> v|oid g(A*|
|000003b0| 20 61 31 2c 20 41 2a 20 | 61 32 29 0a 3e 20 7b 0a | a1, A* |a2).> {.|
|000003c0| 3e 20 20 20 20 20 20 20 | 20 20 61 31 2d 3e 66 28 |> | a1->f(|
|000003d0| 61 32 29 3b 0a 3e 20 7d | 0a 3e 20 0a 3e 20 54 68 |a2);.> }|.> .> Th|
|000003e0| 65 20 61 62 6f 76 65 20 | 63 6f 64 65 20 66 69 72 |e above |code fir|
|000003f0| 73 74 20 6f 66 20 61 6c | 6c 20 77 6f 6e 27 74 20 |st of al|l won't |
|00000400| 63 6f 6d 70 69 6c 65 20 | 75 6e 6c 65 73 73 20 49 |compile |unless I|
|00000410| 20 69 6e 73 65 72 74 20 | 74 68 65 20 66 6f 6c 6c | insert |the foll|
|00000420| 6f 77 69 6e 67 0a 3e 20 | 6c 69 6e 65 20 6f 66 20 |owing.> |line of |
|00000430| 63 6f 64 65 20 69 6e 74 | 6f 20 65 61 63 68 20 63 |code int|o each c|
|00000440| 6c 61 73 73 20 64 65 66 | 69 6e 69 74 69 6f 6e 3a |lass def|inition:|
|00000450| 0a 3e 20 20 20 20 20 20 | 20 20 20 76 69 74 72 75 |.> | vitru|
|00000460| 61 6c 20 76 6f 69 64 20 | 66 28 41 2a 29 20 69 6e |al void |f(A*) in|
|00000470| 20 63 6c 61 73 73 20 41 | 20 6f 72 20 76 6f 69 64 | class A| or void|
|00000480| 20 66 28 41 2a 29 20 69 | 6e 20 63 6c 61 73 73 65 | f(A*) i|n classe|
|00000490| 73 20 42 20 26 20 43 2e | 0a 3e 20 0a 3e 20 54 68 |s B & C.|.> .> Th|
|000004a0| 65 20 6e 65 78 74 20 70 | 72 6f 62 6c 65 6d 20 69 |e next p|roblem i|
|000004b0| 73 20 74 68 61 74 20 74 | 68 65 20 61 62 6f 76 65 |s that t|he above|
|000004c0| 20 6c 69 6e 65 20 66 28 | 41 2a 29 20 69 73 20 74 | line f(|A*) is t|
|000004d0| 68 65 20 66 75 6e 63 74 | 69 6f 6e 20 74 68 61 74 |he funct|ion that|
|000004e0| 20 61 6c 77 61 79 73 0a | 3e 20 67 65 74 73 20 63 | always.|> gets c|
|000004f0| 61 6c 6c 65 64 20 69 6e | 20 74 68 65 20 63 6c 61 |alled in| the cla|
|00000500| 73 73 20 6f 66 20 61 31 | 20 6e 6f 20 6d 61 74 74 |ss of a1| no matt|
|00000510| 65 72 20 77 68 61 74 20 | 61 32 20 69 73 20 69 6e |er what |a2 is in|
|00000520| 20 66 75 6e 63 74 69 6f | 6e 20 67 28 29 2e 20 20 | functio|n g(). |
|00000530| 61 31 0a 3e 20 61 6e 64 | 20 61 32 20 77 69 6c 6c |a1.> and| a2 will|
|00000540| 20 6e 65 76 65 72 20 62 | 65 20 6f 66 20 63 6c 61 | never b|e of cla|
|00000550| 73 73 20 41 2c 20 74 68 | 65 79 20 77 69 6c 6c 20 |ss A, th|ey will |
|00000560| 6f 6e 6c 79 20 62 65 20 | 6f 66 20 65 69 74 68 65 |only be |of eithe|
|00000570| 72 20 63 6c 61 73 73 20 | 42 20 6f 72 0a 3e 20 63 |r class |B or.> c|
|00000580| 6c 61 73 73 20 43 2c 20 | 73 6f 20 49 27 6d 20 6e |lass C, |so I'm n|
|00000590| 6f 74 20 73 75 72 65 20 | 77 68 79 20 74 68 65 20 |ot sure |why the |
|000005a0| 74 68 65 20 63 61 6c 6c | 20 61 31 2d 3e 66 28 61 |the call| a1->f(a|
|000005b0| 32 29 20 61 6c 77 61 79 | 73 20 63 61 6c 6c 73 20 |2) alway|s calls |
|000005c0| 74 68 65 0a 3e 20 66 75 | 6e 63 74 69 6f 6e 20 66 |the.> fu|nction f|
|000005d0| 28 41 2a 29 20 69 6e 20 | 74 68 65 20 63 6c 61 73 |(A*) in |the clas|
|000005e0| 73 20 6f 66 20 61 31 2c | 20 61 6e 64 20 6e 6f 74 |s of a1,| and not|
|000005f0| 20 66 28 42 2a 29 20 6f | 72 20 66 28 43 2a 29 20 | f(B*) o|r f(C*) |
|00000600| 64 65 70 65 6e 64 69 6e | 67 20 6f 6e 0a 3e 20 77 |dependin|g on.> w|
|00000610| 68 61 74 20 63 6c 61 73 | 73 20 61 32 20 69 73 2e |hat clas|s a2 is.|
|00000620| 0a 3e 20 0a 3e 20 41 6e | 79 20 68 65 6c 70 20 69 |.> .> An|y help i|
|00000630| 6e 20 73 6f 6c 76 69 6e | 67 20 74 68 69 73 20 70 |n solvin|g this p|
|00000640| 72 6f 62 6c 65 6d 20 77 | 6f 75 6c 64 20 62 65 20 |roblem w|ould be |
|00000650| 61 70 70 72 65 63 69 61 | 74 65 64 2e 0a 3e 20 0a |apprecia|ted..> .|
|00000660| 3e 20 49 61 6e 2e 0a 0a | 54 6f 20 72 65 73 70 6f |> Ian...|To respo|
|00000670| 6e 64 20 74 6f 20 79 6f | 75 72 20 71 75 65 73 74 |nd to yo|ur quest|
|00000680| 69 6f 6e 2c 20 49 20 61 | 6d 20 61 73 73 75 6d 69 |ion, I a|m assumi|
|00000690| 6e 67 20 74 68 65 20 66 | 6f 6c 6c 6f 77 69 6e 67 |ng the f|ollowing|
|000006a0| 20 6d 61 69 6e 20 70 72 | 6f 67 72 61 6d 0a 74 6f | main pr|ogram.to|
|000006b0| 20 75 73 65 20 79 6f 75 | 72 20 63 6f 64 65 20 64 | use you|r code d|
|000006c0| 65 63 6c 61 72 61 74 69 | 6f 6e 2e 0a 0a 69 6e 74 |eclarati|on...int|
|000006d0| 20 6d 61 69 6e 28 29 0a | 7b 0a 09 42 20 62 31 2c | main().|{..B b1,|
|000006e0| 62 32 3b 0a 09 43 20 63 | 31 2c 63 32 3b 0a 2f 2f |b2;..C c|1,c2;.//|
|000006f0| 20 34 20 63 6f 6d 62 69 | 6e 61 74 69 6f 6e 73 20 | 4 combi|nations |
|00000700| 6f 66 20 63 61 6c 6c 69 | 6e 67 20 67 20 62 61 73 |of calli|ng g bas|
|00000710| 65 64 20 6f 6e 20 70 6f | 73 73 69 62 6c 65 0a 2f |ed on po|ssible./|
|00000720| 2f 20 64 61 74 61 20 74 | 79 70 65 73 20 74 6f 20 |/ data t|ypes to |
|00000730| 62 65 20 70 61 73 73 65 | 64 0a 0a 09 67 28 26 62 |be passe|d...g(&b|
|00000740| 31 2c 26 62 32 29 3b 20 | 20 2f 2f 20 43 61 6c 6c |1,&b2); | // Call|
|00000750| 20 66 75 6e 63 74 69 6f | 6e 20 66 28 42 2a 29 20 | functio|n f(B*) |
|00000760| 69 6e 20 63 6c 61 73 73 | 20 42 0a 09 67 28 26 62 |in class| B..g(&b|
|00000770| 31 2c 26 63 31 29 3b 20 | 20 2f 2f 20 43 61 6c 6c |1,&c1); | // Call|
|00000780| 20 66 75 6e 63 74 69 6f | 6e 20 66 28 43 2a 29 20 | functio|n f(C*) |
|00000790| 69 6e 20 63 6c 61 73 73 | 20 42 0a 09 67 28 26 63 |in class| B..g(&c|
|000007a0| 31 2c 26 62 31 29 3b 20 | 20 2f 2f 20 43 61 6c 6c |1,&b1); | // Call|
|000007b0| 20 66 75 6e 63 74 69 6f | 6e 20 66 28 42 2a 29 20 | functio|n f(B*) |
|000007c0| 69 6e 20 63 6c 61 73 73 | 20 43 0a 09 67 28 26 63 |in class| C..g(&c|
|000007d0| 31 2c 26 63 32 29 3b 20 | 20 2f 2f 20 43 61 6c 6c |1,&c2); | // Call|
|000007e0| 20 66 75 6e 63 74 69 6f | 6e 20 66 28 43 2a 29 20 | functio|n f(C*) |
|000007f0| 69 6e 20 63 6c 61 73 73 | 20 43 0a 7d 0a 54 68 65 |in class| C.}.The|
|00000800| 20 63 6f 6d 70 69 6c 65 | 72 20 69 73 20 72 65 73 | compile|r is res|
|00000810| 70 6f 6e 64 69 6e 67 20 | 77 69 74 68 20 74 68 65 |ponding |with the|
|00000820| 20 74 68 65 20 65 72 72 | 6f 72 20 6d 65 73 73 61 | the err|or messa|
|00000830| 67 65 20 62 65 63 61 75 | 73 65 20 69 6e 73 69 64 |ge becau|se insid|
|00000840| 65 0a 74 68 65 20 66 75 | 6e 63 74 69 6f 6e 20 67 |e.the fu|nction g|
|00000850| 2c 20 69 74 20 69 73 20 | 6f 6e 6c 79 20 61 77 61 |, it is |only awa|
|00000860| 72 65 20 6f 66 20 74 68 | 65 20 64 61 74 61 20 74 |re of th|e data t|
|00000870| 79 70 65 73 20 6f 66 20 | 74 68 65 20 74 77 6f 20 |ypes of |the two |
|00000880| 0a 61 72 67 75 6d 65 6e | 74 73 20 61 31 2c 20 61 |.argumen|ts a1, a|
|00000890| 6e 64 20 61 32 20 77 68 | 69 63 68 20 69 73 20 41 |nd a2 wh|ich is A|
|000008a0| 2a 2c 20 61 66 74 65 72 | 20 63 61 73 74 69 6e 67 |*, after| casting|
|000008b0| 20 74 68 65 20 61 72 75 | 67 6d 65 6e 74 73 20 66 | the aru|gments f|
|000008c0| 6f 72 0a 75 73 65 20 69 | 6e 20 74 68 65 20 66 75 |or.use i|n the fu|
|000008d0| 6e 63 74 69 6f 6e 2e 20 | 20 49 6e 20 6f 74 68 65 |nction. | In othe|
|000008e0| 72 20 77 6f 72 64 73 2c | 20 74 68 65 20 61 72 75 |r words,| the aru|
|000008f0| 67 6d 65 6e 74 73 20 75 | 73 65 64 20 69 6e 73 69 |gments u|sed insi|
|00000900| 64 65 20 74 68 65 0a 66 | 75 6e 63 74 69 6f 6e 20 |de the.f|unction |
|00000910| 67 2c 20 6c 6f 73 65 20 | 61 6c 6c 20 72 65 63 6f |g, lose |all reco|
|00000920| 67 6e 69 74 69 6f 6e 20 | 6f 66 20 74 68 65 20 61 |gnition |of the a|
|00000930| 63 74 75 61 6c 20 6f 62 | 6a 65 63 74 73 20 74 68 |ctual ob|jects th|
|00000940| 65 79 20 70 6f 69 6e 74 | 65 64 0a 74 6f 2e 20 20 |ey point|ed.to. |
|00000950| 54 6f 20 67 65 74 20 74 | 68 65 20 66 75 6e 63 74 |To get t|he funct|
|00000960| 69 6f 6e 61 6c 69 74 79 | 20 69 74 20 61 70 70 65 |ionality| it appe|
|00000970| 61 72 73 20 79 6f 75 20 | 77 61 6e 74 20 61 6e 64 |ars you |want and|
|00000980| 20 61 73 20 49 20 68 61 | 76 65 0a 73 68 6f 77 6e | as I ha|ve.shown|
|00000990| 20 70 6f 73 73 69 62 69 | 6c 69 74 69 65 73 20 61 | possibi|lities a|
|000009a0| 62 6f 76 65 20 69 6e 20 | 6d 61 69 6e 2c 20 74 77 |bove in |main, tw|
|000009b0| 6f 20 73 6f 6c 75 74 69 | 6f 6e 73 20 63 6f 6d 65 |o soluti|ons come|
|000009c0| 20 74 6f 20 6d 69 6e 64 | 2e 20 20 0a 0a 46 69 72 | to mind|. ..Fir|
|000009d0| 73 74 2c 20 63 72 65 61 | 74 65 20 61 20 6d 61 63 |st, crea|te a mac|
|000009e0| 72 6f 20 66 6f 72 20 66 | 75 6e 63 74 69 6f 6e 20 |ro for f|unction |
|000009f0| 67 20 6c 69 6b 65 3a 0a | 0a 23 64 65 66 69 6e 65 |g like:.|.#define|
|00000a00| 20 67 28 61 31 2c 61 32 | 29 20 20 28 28 61 31 29 | g(a1,a2|) ((a1)|
|00000a10| 2d 3e 28 61 32 29 29 0a | 0a 53 65 63 6f 6e 64 2c |->(a2)).|.Second,|
|00000a20| 20 6d 61 6b 65 20 67 20 | 61 20 74 65 6d 70 6c 61 | make g |a templa|
|00000a30| 74 65 20 66 75 6e 63 74 | 69 6f 6e 20 61 6e 64 20 |te funct|ion and |
|00000a40| 6d 61 6b 65 20 63 6c 61 | 73 73 20 41 20 61 6e 20 |make cla|ss A an |
|00000a50| 61 62 73 74 72 61 63 74 | 20 62 61 73 65 0a 63 6c |abstract| base.cl|
|00000a60| 61 73 73 20 28 69 65 20 | 69 74 20 68 61 73 20 70 |ass (ie |it has p|
|00000a70| 75 72 65 20 76 69 72 74 | 75 61 6c 20 66 75 6e 63 |ure virt|ual func|
|00000a80| 74 69 6f 6e 73 20 69 6e | 73 69 64 65 20 69 74 29 |tions in|side it)|
|00000a90| 20 73 69 6e 63 65 20 79 | 6f 75 20 73 61 69 64 0a | since y|ou said.|
|00000aa0| 66 75 6e 63 74 69 6f 6e | 20 67 20 77 69 6c 6c 20 |function| g will |
|00000ab0| 6e 65 76 65 72 20 61 63 | 74 75 61 6c 6c 79 20 67 |never ac|tually g|
|00000ac0| 65 74 20 73 65 6e 74 20 | 6f 62 6a 65 63 74 73 20 |et sent |objects |
|00000ad0| 6f 66 20 63 6c 61 73 73 | 20 41 2e 0a 0a 53 65 65 |of class| A...See|
|00000ae0| 20 65 6e 74 69 72 65 20 | 63 6f 64 65 20 62 65 6c | entire |code bel|
|00000af0| 6f 77 3a 0a 0a 23 69 6e | 63 6c 75 64 65 20 3c 69 |ow:..#in|clude <i|
|00000b00| 6f 73 74 72 65 61 6d 2e | 68 3e 0a 63 6c 61 73 73 |ostream.|h>.class|
|00000b10| 20 42 3b 0a 63 6c 61 73 | 73 20 43 3b 0a 0a 63 6c | B;.clas|s C;..cl|
|00000b20| 61 73 73 20 41 0a 7b 0a | 70 75 62 6c 69 63 3a 0a |ass A.{.|public:.|
|00000b30| 20 20 20 76 69 72 74 75 | 61 6c 20 76 6f 69 64 20 | virtu|al void |
|00000b40| 66 28 42 2a 29 3d 30 3b | 20 2f 2f 70 75 72 65 20 |f(B*)=0;| //pure |
|00000b50| 76 69 72 74 75 61 6c 20 | 66 75 6e 63 74 69 6f 6e |virtual |function|
|00000b60| 73 20 74 6f 20 6d 61 6b | 65 20 63 6c 61 73 73 20 |s to mak|e class |
|00000b70| 41 20 0a 20 20 20 76 69 | 72 74 75 61 6c 20 76 6f |A . vi|rtual vo|
|00000b80| 69 64 20 66 28 43 2a 29 | 3d 30 3b 20 2f 2f 20 61 |id f(C*)|=0; // a|
|00000b90| 6e 20 61 62 73 74 72 61 | 63 74 20 62 61 73 65 20 |n abstra|ct base |
|00000ba0| 63 6c 61 73 73 0a 7d 3b | 0a 0a 63 6c 61 73 73 20 |class.};|..class |
|00000bb0| 42 3a 20 70 75 62 6c 69 | 63 20 41 0a 7b 0a 70 75 |B: publi|c A.{.pu|
|00000bc0| 62 6c 69 63 3a 0a 20 20 | 20 76 6f 69 64 20 66 28 |blic:. | void f(|
|00000bd0| 42 2a 29 20 7b 63 6f 75 | 74 20 3c 3c 20 22 49 4e |B*) {cou|t << "IN|
|00000be0| 20 42 20 63 61 6c 6c 69 | 6e 67 20 66 42 22 20 3c | B calli|ng fB" <|
|00000bf0| 3c 20 65 6e 64 6c 3b 7d | 20 2f 2f 74 65 73 74 20 |< endl;}| //test |
|00000c00| 77 68 69 63 68 20 66 75 | 6e 63 74 69 6f 6e 0a 20 |which fu|nction. |
|00000c10| 20 20 76 6f 69 64 20 66 | 28 43 2a 29 20 7b 63 6f | void f|(C*) {co|
|00000c20| 75 74 20 3c 3c 20 22 49 | 4e 20 42 20 63 61 6c 6c |ut << "I|N B call|
|00000c30| 69 6e 67 20 66 43 22 20 | 3c 3c 20 65 6e 64 6c 3b |ing fC" |<< endl;|
|00000c40| 7d 20 2f 2f 20 67 65 74 | 73 20 63 61 6c 6c 65 64 |} // get|s called|
|00000c50| 0a 7d 3b 0a 0a 63 6c 61 | 73 73 20 43 3a 20 70 75 |.};..cla|ss C: pu|
|00000c60| 62 6c 69 63 20 41 0a 7b | 0a 70 75 62 6c 69 63 3a |blic A.{|.public:|
|00000c70| 0a 20 20 20 76 6f 69 64 | 20 66 28 42 2a 29 20 7b |. void| f(B*) {|
|00000c80| 63 6f 75 74 20 3c 3c 20 | 22 49 4e 20 43 20 63 61 |cout << |"IN C ca|
|00000c90| 6c 6c 69 6e 67 20 66 42 | 22 20 3c 3c 20 65 6e 64 |lling fB|" << end|
|00000ca0| 6c 3b 7d 0a 20 20 20 76 | 6f 69 64 20 66 28 43 2a |l;}. v|oid f(C*|
|00000cb0| 29 20 7b 63 6f 75 74 20 | 3c 3c 20 22 49 4e 20 43 |) {cout |<< "IN C|
|00000cc0| 20 63 61 6c 6c 69 6e 67 | 20 66 43 22 20 3c 3c 20 | calling| fC" << |
|00000cd0| 65 6e 64 6c 3b 7d 0a 7d | 3b 0a 0a 74 65 6d 70 6c |endl;}.}|;..templ|
|00000ce0| 61 74 65 20 3c 63 6c 61 | 73 73 20 54 31 2c 20 63 |ate <cla|ss T1, c|
|00000cf0| 6c 61 73 73 20 54 32 3e | 20 20 20 2f 2f 20 68 65 |lass T2>| // he|
|00000d00| 72 65 20 69 73 20 74 68 | 65 20 74 65 6d 70 6c 61 |re is th|e templa|
|00000d10| 74 65 0a 76 6f 69 64 20 | 67 28 54 31 2a 20 61 31 |te.void |g(T1* a1|
|00000d20| 2c 20 54 32 2a 20 61 32 | 29 0a 7b 0a 20 20 20 20 |, T2* a2|).{. |
|00000d30| 61 31 2d 3e 66 28 61 32 | 29 3b 0a 7d 0a 0a 23 64 |a1->f(a2|);.}..#d|
|00000d40| 65 66 69 6e 65 20 68 28 | 61 31 2c 61 32 29 20 28 |efine h(|a1,a2) (|
|00000d50| 28 61 31 29 2d 3e 66 28 | 61 32 29 29 20 20 2f 2f |(a1)->f(|a2)) //|
|00000d60| 20 68 65 72 65 20 69 73 | 20 74 68 65 20 6d 61 63 | here is| the mac|
|00000d70| 72 6f 20 63 61 6c 6c 65 | 64 20 68 20 74 6f 0a 09 |ro calle|d h to..|
|00000d80| 09 09 09 2f 2f 20 61 76 | 6f 69 64 20 63 6f 6e 66 |...// av|oid conf|
|00000d90| 6c 69 63 74 73 20 77 69 | 74 68 20 66 75 6e 63 74 |licts wi|th funct|
|00000da0| 69 6f 6e 20 67 0a 09 09 | 09 09 2f 2f 20 69 6e 20 |ion g...|..// in |
|00000db0| 74 68 65 20 73 61 6d 65 | 20 73 6f 75 72 63 65 20 |the same| source |
|00000dc0| 66 69 6c 65 0a 0a 69 6e | 74 20 6d 61 69 6e 28 29 |file..in|t main()|
|00000dd0| 0a 7b 0a 20 20 20 20 42 | 20 62 3b 0a 20 20 20 20 |.{. B| b;. |
|00000de0| 43 20 63 3b 0a 20 20 20 | 20 67 28 26 62 2c 26 63 |C c;. | g(&b,&c|
|00000df0| 29 3b 0a 20 20 20 20 68 | 28 20 26 63 2c 20 26 62 |);. h|( &c, &b|
|00000e00| 20 29 3b 0a 0a 48 6f 70 | 65 20 69 74 20 68 65 6c | );..Hop|e it hel|
|00000e10| 70 73 2e 0a 2d 2d 20 0a | 4a 6f 65 6c 20 43 2e 20 |ps..-- .|Joel C. |
|00000e20| 57 65 6e 67 65 72 0a 48 | 65 77 6c 65 74 74 20 50 |Wenger.H|ewlett P|
|00000e30| 61 63 6b 61 72 64 20 43 | 6f 2e 0a 6a 77 65 6e 67 |ackard C|o..jweng|
|00000e40| 65 72 40 61 34 34 33 30 | 65 64 63 2e 65 73 72 2e |er@a4430|edc.esr.|
|00000e50| 68 70 2e 63 6f 6d 0a 57 | 6f 72 6b 20 50 68 6f 6e |hp.com.W|ork Phon|
|00000e60| 65 3a 20 28 33 30 31 29 | 20 36 37 30 2d 34 35 32 |e: (301)| 670-452|
|00000e70| 32 0a 57 6f 72 6b 20 46 | 61 78 3a 20 28 33 30 31 |2.Work F|ax: (301|
|00000e80| 29 20 39 32 31 2d 36 32 | 31 37 0a 0a 41 6c 6c 20 |) 921-62|17..All |
|00000e90| 73 74 61 74 65 6d 65 6e | 74 73 20 65 78 70 72 65 |statemen|ts expre|
|00000ea0| 73 73 65 64 20 61 62 6f | 76 65 20 61 72 65 20 6d |ssed abo|ve are m|
|00000eb0| 79 20 6f 77 6e 2c 20 6e | 6f 74 20 6d 79 20 65 6d |y own, n|ot my em|
|00000ec0| 70 6c 6f 79 65 72 27 73 | 0a |ployer's|. |
+--------+-------------------------+-------------------------+--------+--------+